<?php 
class product_plugin_related extends abstract_product_plugin {
 
    public function getProductRelated($product_id) {
		$product_data = array();

		$query = $this->pdo->prepare("SELECT * FROM " . $this->db_prefix . "product_related pr 
            LEFT JOIN " . $this->db_prefix . "product p 
            ON (pr.related_id = p.product_id) 

            LEFT JOIN " . $this->db_prefix . "product_description pd 
            ON (p.product_id = pd.product_id) 

            LEFT JOIN " . $this->db_prefix . "product_to_store p2s 
            ON (p.product_id = p2s.product_id) 
            WHERE pr.product_id = :product_id 
            AND p.status = '1' 
            AND p.date_available <= NOW() 
            AND p2s.store_id = :store_id");

        $query->execute(array(
            ':product_id'   => $product_id,
            ':store_id'     => $this->site_id
        ));

        while ($product = $query->fetchObject('class_product')) {
            $product_data[$product->get_id()] = $product;	
        }

        return $product_data;
    }
}
